<?php

namespace backend\components\widgets\ztree;
use Yii;
use yii\base\Widget;
use backend\components\widgets\ztree\ZtreeAsset;
/**
 * Description of ZtreeWidget
 *
 * @author zhuo bing
 */
class ZtreeWidget extends Widget{
    public $data;
    public function run(){
        $view = $this->getView();
        $this->registerBundle($view);
        $this->renderJs($view);
        echo '<div class="panel panel-primary">'
                .' <div class="panel-heading">'
                    .'<h3 class="panel-title" ><i class="fa fa-tree"></i>&nbsp;'.Yii::t('common','Category').'</h3>'
                .'</div>'
                . '<div class="panel-body">'
                    . '<ul id="treeDemo" class="ztree" ></ul>'
                . '</div>'
           . '</div>';
        
    }
    protected function registerBundle($view){
        ZtreeAsset::register($view);
    }
    protected function renderJs($view){
        $js = <<<js
            var zTreeObj;
            // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
            var setting = {};
            // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
            var zNodes = $this->data;
            zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
js;
        $view->registerJs($js);
    }
}
